const express = require("express");
const app = express(); //s实例化一个app

const cors = require('cors');//导入cors中间件
app.use(cors());//将cores注册为全局中间件

const bodyParser = require('body-parser');//引入body-parse
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());// 使用body-parser配置解析表单的中间件


app.get("/",(req,res) => {
    res.send("HEllO!!")
})


// 处理管理员(&用户)登录注册相关的路由
const adminRouter = require('./routes/admin')
app.use('/api/admin', adminRouter)


// 调用app.listen方法，指定端口号并启动web服务器
const port = process.env.PORT || 5000;
app.listen(port,()=>{
    console.log(`Serve is running on port ${port}`);

})
//处理普通用户的路由
const userRouter = require('./routes/userInfo');
app.use('/api/user', userRouter);

const mallRouter = require('./routes/mall');
app.use('/api/mall',mallRouter);

const phoneRouter = require('./routes/phone');
app.use('/api/phone',phoneRouter);

const fundRouter = require('./routes/funds');
app.use('/api/funds',fundRouter);